package hello.word.m2.maven.dao;

import hello.word.m2.maven.domain.Book;
import hello.word.m2.maven.support.AutoSqlObject;
//import lombok.NonNull;
import org.jdbi.v3.core.Handle;
import org.jdbi.v3.core.Jdbi;
import org.jdbi.v3.core.statement.OutParameters;

import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.List;

@Singleton
public class BookDaoImpl implements BookDao {

    private final Jdbi jdbi;

//    @Inject
    public BookDaoImpl(Jdbi jdbi) {
        this.jdbi = jdbi;
    }

    BookDao getDao(){
        return (BookDao)jdbi.getConfig(AutoSqlObject.class).getObject(BookDao.class.getName());
    }

    @Override
    public int insert(long id, String name) {
        return getDao().insert(id,name);
    }

    @Override
    public int update(long id, String name) {
        return getDao().update(id,name);
    }

    @Override
    public List<Book> selectAll() {
        return getDao().selectAll();
    }

    @Override
    public List<Book> selectByIdAndName(long id, String name) {
        return getDao().selectByIdAndName(id,name);
    }

    @Override
    public List<Book> selectAll2() {
        return getDao().selectAll2();
    }

    @Override
    public List<Book> selectAll(boolean sort, String sortBy) {
        return getDao().selectAll(sort,sortBy);
    }

    @Override
    public List<Book> selectAll(String name, String sortBy) {
        return getDao().selectAll(name,sortBy);
    }

    @Override
    public void callDemoProceduce(int p_inout) {
        getDao().callDemoProceduce(p_inout);
    }

    @Override
    public OutParameters callDemoProceduce2(int p_inout) {
        return getDao().callDemoProceduce2(p_inout);
    }

    @Override
    public List<Book> findByIdOrFirstName(Long id, String name) {
        return getDao().findByIdOrFirstName(id,name);
    }

    @Override
    public List<Book> findById(Long id) {
        return getDao().findById(id);
    }

    @Override
    public List<Book> findByFirstNameLike(String name) {
        return getDao().findByFirstNameLike(name);
    }

    @Override
    public long internalCount(String tableName) {
        return getDao().internalCount(tableName);
    }

    @Override
    public List<Book> internalFindAll(String tableName, String idColumnName, OrderType orderType, int limit) {
        return getDao().internalFindAll(tableName,idColumnName,orderType,limit);
    }

    @Override
    public List<Book> internalFindConditions(String tableName, String conditions, String idColumnName) {
        return getDao().internalFindConditions( tableName,  conditions,  idColumnName);
    }

    @Override
    public int internalUpdateConditions(String tableName, String columnName, Object value, String conditions) {
        return getDao().internalUpdateConditions( tableName,  columnName,  value,  conditions);
    }

    @Override
    public List<Book> internalFind(String tableName, String column, @Nullable Object value, String operand, String idColumnName) {
        return getDao().internalFind( tableName,  column,   value,  operand,  idColumnName);
    }

    @Override
    public void internalTruncate(String tableName) {
        getDao().internalTruncate(tableName);
    }

    @Override
    public int internalDelete(String tableName, String idColumnName, /*@NonNull*/ Long aLong) {
        return getDao().internalDelete(tableName,idColumnName,aLong);
    }

    @Override
    public void internalInsert(String tableName, List<String> columnList, List<Object> valueList) {
        getDao().internalInsert(tableName,columnList,valueList);
    }

    @Override
    public Long internalInsertReturnID(String tableName, List<String> columnList, List<Object> valueList) {
        return getDao().internalInsertReturnID( tableName,  columnList,  valueList);
    }

    @Override
    public void internalUpdate(String tableName, String columnName, @Nullable Object value, String idColumnName, /*@NonNull*/ Long aLong) {
        getDao().internalUpdate( tableName,  columnName,   value,  idColumnName,   aLong);
    }

    @Override
    public int internalUpdateAll(String tableName, String columnName, @Nullable Object value) {
        return getDao().internalUpdateAll( tableName,  columnName,   value) ;
    }

    @Override
    public Handle getHandle() {
        return getDao().getHandle();
    }
}
